package com.sdo.qihang.gprogress.lib;

import android.content.Context;
import android.content.res.Resources;
import android.util.TypedValue;

public class Utils {
    public static int dp2Px(float dp, Context context) {
        return dp2Px(dp, context.getResources());
    }

    public static int dp2Px(float dp, Resources resources) {
        float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics());
        return (int) px;
    }

    public static int sp2px(int spVal, Context context) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
                spVal, context.getResources().getDisplayMetrics());

    }

    public static int px2Dp(float px, Resources resources) {
        float dp = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, px, resources.getDisplayMetrics());
        return (int) dp;
    }

    public static int px2Dp(float px, Context context) {
        return px2Dp(px, context.getResources());
    }
}
